Skip to content

Add Phi-4-mini-instruct support (MIT, 3.8B) - #75

Closed
stikves wants to merge 1 commit into
apple:mainfrom
stikves:sukru/phi4-opt
Closed

Add Phi-4-mini-instruct support (MIT, 3.8B)#75
stikves wants to merge 1 commit into
apple:mainfrom
stikves:sukru/phi4-opt

Conversation

@stikves

@stikves stikves commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Add Microsoft Phi-4-mini-instruct for on-device inference. MIT licensed, 3.8B parameters, strong quality for reasoning, coding, and math tasks.

Changes

  • python/src/coreai_models/models/macos/phi3.py — New model class (Phi-3/4-mini architecture)
  • Registry entry (phi3 model_type)
  • Preset: phi-4-mini-instruct defaulting to INT4 quantization
  • models/phi4/README.md — Usage documentation

Architecture

  • model_type: phi3 (shared across Phi-3, 3.5, 4-mini)
  • 32 layers, 3072 hidden, GQA (24 heads / 8 KV heads), head_dim=128
  • Partial rotary embedding (75% of head_dim)
  • Fused gate_up_proj split at export time to reuse standard MLP primitive
  • Longrope attention_factor for extended context support
  • tie_word_embeddings (lm_head shares embed_tokens weight)

Performance (Apple Silicon)

Variant Prefill (t/s) Generation (t/s) Size
INT4 (default) ~253 ~108 ~2 GB
FP16 ~32 ~38 ~7.6 GB

Export

uv run coreai.llm.export microsoft/Phi-4-mini-instruct

Test plan

  • Model loads from HuggingFace weights
  • Export completes (INT4 and FP16)
  • E2E inference produces coherent output
  • Argmax matches HF reference (2-layer parity test)
  • Full PSNR verification

Microsoft Phi-4-mini for on-device inference. MIT licensed, strong
quality for its size (reasoning, coding, math).

Architecture:
- model_type: phi3 (shared across Phi-3/3.5/4-mini)
- 32 layers, 3072 hidden, 24 heads / 8 KV heads, head_dim=128
- Partial rotary embedding (75% of head_dim = 96 dims)
- Fused gate_up_proj split at export time
- Longrope attention_factor (1.19) for extended context
- tie_word_embeddings (lm_head = embed_tokens)

Performance (Apple Silicon):
- INT4: ~253 t/s prefill, ~108 t/s generation (~2GB)
- FP16: ~32 t/s prefill, ~38 t/s generation (~7.6GB)

Default preset uses INT4 quantization for best on-device experience.
@stikves stikves closed this Jul 2, 2026
@stikves
stikves deleted the sukru/phi4-opt branch July 2, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant